package com.wwc.sc.service;

import com.wwc.sc.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService> {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public int addDept(Dept dept) {
                return 0;
            }

            @Override
            public Dept queryDept(String deptNo) {
                Dept dept = new Dept();
                dept.setDeptNo(deptNo);
                dept.setDeptName("deptNo = "+deptNo+" 客户端提供降级服务，该服务已被关闭！");
                dept.setScSource("已降级！");
                return dept;
            }

            @Override
            public List<Dept> queryAllDept() {
                List<Dept> deptList = new ArrayList();
                Dept dept = new Dept();
                dept.setDeptNo("404");
                dept.setDeptName("deptNo = "+dept.getDeptNo()+" 客户端提供降级服务，该服务已被关闭！");
                dept.setScSource("已降级！");

                deptList.add(dept);
                deptList.add(dept);
                deptList.add(dept);

                return deptList;
            }
        };
    }
}
